//
//  UITextField+YDYExtension.h
//  DYSisterAPP
//
//  Created by 杨德勇 on 16/7/27.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "UIView+YDYExtension.h"

@implementation UIView (YDYExtension)

- (CGSize)ydy_size
{
    return self.frame.size;
}

- (void)setYdy_size:(CGSize)ydy_size
{
    CGRect frame = self.frame;
    frame.size = ydy_size;
    self.frame = frame;
}

- (CGFloat)ydy_width
{
    return self.frame.size.width;
}

- (CGFloat)ydy_height
{
    return self.frame.size.height;
}

- (void)setYdy_width:(CGFloat)ydy_width
{
    CGRect frame = self.frame;
    frame.size.width = ydy_width;
    self.frame = frame;
}

- (void)setYdy_height:(CGFloat)ydy_height
{
    CGRect frame = self.frame;
    frame.size.height = ydy_height;
    self.frame = frame;
}

- (CGFloat)ydy_x
{
    return self.frame.origin.x;
}

- (void)setYdy_x:(CGFloat)ydy_x
{
    CGRect frame = self.frame;
    frame.origin.x = ydy_x;
    self.frame = frame;
}

- (CGFloat)ydy_y
{
    return self.frame.origin.y;
}

- (void)setYdy_y:(CGFloat)ydy_y
{
    CGRect frame = self.frame;
    frame.origin.y = ydy_y;
    self.frame = frame;
}

- (CGFloat)ydy_centerX
{
    return self.center.x;
}

- (void)setYdy_centerX:(CGFloat)ydy_centerX
{
    CGPoint center = self.center;
    center.x = ydy_centerX;
    self.center = center;
}

- (CGFloat)ydy_centerY
{
    return self.center.y;
}

- (void)setYdy_centerY:(CGFloat)ydy_centerY
{
    CGPoint center = self.center;
    center.y = ydy_centerY;
    self.center = center;
}

- (CGFloat)ydy_right
{

    return CGRectGetMaxX(self.frame);
}

- (CGFloat)ydy_bottom
{

    return CGRectGetMaxY(self.frame);
}

- (void)setYdy_right:(CGFloat)ydy_right
{
    self.ydy_x = ydy_right - self.ydy_width;
}

- (void)setYdy_bottom:(CGFloat)ydy_bottom
{
    self.ydy_y = ydy_bottom - self.ydy_height;
}

+(instancetype)ydy_viewfromXib{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

- (BOOL)ydy_intersectWithView:(UIView *)view{
    //参考物
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    CGRect selfRect = [self convertRect:self.bounds toView:window];
    CGRect viewRect = [view convertRect:view.bounds toView:window];
    
    return  CGRectIntersectsRect(selfRect, viewRect);
}

@end
